<?php

namespace models;

use Unirest\Request;

class Weixin {

	/** 获取access_token **/
	public static function getAccessToken($code) {
		$appid = C_APPID;
		$secret = C_APPSECRET;
		$response = Request::get("https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$secret&code=$code&grant_type=authorization_code");
		
		if($response->code == 200) {
			return $response->body;
		}
    }

    /** 获取用户信息 **/
	public static function getUserinfo($accessToken, $openid) {
		$response = Request::get("https://api.weixin.qq.com/sns/userinfo?access_token=$accessToken&openid=$openid&lang=zh_CN");
		
		if($response->code == 200) {
			return $response->body;
		}
    }
    
}

